home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / xv_pc17.zip / XVIEW_PC.TXT < prev    next >
Text File  |  1994-08-03  |  36KB  |  727 lines

  1. XView-PC: Graphical User Interface for Pascal/C/C++
  2. ---------------------------------------------------
  3.  
  4. By:
  5. Antonio Carlos Moreirao de Queiroz
  6. Department of Electronic Engineering and COPPE
  7. Federal University of Rio de Janeiro, Brazil
  8. e-mail: acmq@coe.ufrj.br
  9.  
  10. INTRODUCTION
  11. ------------
  12.  
  13.   The XView-PC graphical user interface attempts to be similar to the XView
  14. toolkit used in Sun workstations, in a simplified form.
  15.   The interface was initially developed as an intermediate step in porting
  16. programs from the PC to Sun workstations, by implementing a subset of the
  17. Sun XView toolkit in the PC. The work was not completed because it soon
  18. become clear that a total translation would be unnecessarily complex. Even
  19. so, the working of the two interfaces was kept similar when reasonable.
  20.   What can be done with the interface in its present form can be repeated
  21. with the Sun XView without significant structural changes, although with
  22. differences due to the various simplifications made. The porting of an
  23. application to Windows is also not complex.
  24.  
  25.   The archive file "xv_pc*.zip" contains the versions:
  26.  
  27. - Borland Pascal 7.0, Real mode.
  28.   Files "mickey.tpu", "xview.tpu"
  29. - Borland Pascal 7.0, Protected mode.
  30.   Files "mickey.tpp", "xview.tpp"
  31. - Borland C/C++, Real mode.
  32.   Files "mickey.h", "mickey.obj", "xview.h", "xview.obj"
  33. - GNU C (djgpp), Protected mode.
  34.   Files "mickey,h", "mickey.o", "xview.h", "xview.o"
  35.  
  36.   The file contains also several examples and utilities in Pascal and C.
  37.  
  38.   The interface is the same in any of the versions.
  39.   The interface code is of simple use and adds only about 25 k to the
  40. executable program doing all the user interface functions. It works with any
  41. PC compatible computer, in any graphics mode supported by the BGI drivers and
  42. installed mouse driver. If a mouse is not installed, a mouse emulator using
  43. the keyboard is automatically used.
  44.   To simplify the interface code generation, an interface editor program,
  45. "x_make", is included. It allows the edition of a complete user
  46. interface, and the automatic generation of an skeleton program in Pascal or
  47. C, that is a fully functional program that the user can edit and complete.
  48.  
  49. TYPICAL PROGRAM STRUCTURE
  50. -------------------------
  51.  
  52.   Below is the structure of a typical program using the interface:
  53.  
  54. - Program header:
  55. - Declaration of global variables and interface "objects".
  56. - Normal subroutines.
  57. - Subroutines called from the interface objects ("callbacks").
  58. - Main program:
  59. - Normal initialization.
  60. - Interface initialization: call to "xv_init".
  61. - Creation and initialization of the interface objects: calls to
  62.   "xv_create" followed by direct initialization of the object parameters.
  63. - Passing of control to the interface "notifier": call to "xv_main_loop".
  64. - Normal termination.
  65.  
  66. INTERFACE OBJECTS
  67. -----------------
  68.  
  69.   The user interface is composed of "objects". Note that the interface was
  70. not programmed with "object-oriented" specific techniques, but some ideas
  71. are used.
  72.   There are eight types of predefined objects, listed below. Their names
  73. are the parameters to be passed to the "xv_create" procedure.
  74.  
  75. - "frame":     Base windows, where the other objects are.
  76. - "button":    Command buttons.
  77. - "textfield": Input fields for text and numerical values, with edition.
  78. - "setting":   Input fields for logical values (choices).
  79. - "message":   Messages or icons in the windows.
  80. - "canvas":    Graphical output subwindows.
  81. - "tty":       Text output subwindows.
  82. - "menu":      Pop-up menus.
  83.  
  84.   Other types of objects can be programmed, if necessary, by adding the
  85. desired functionality to "canvas" objects through their "callback"
  86. routines. See the example program "rotor.pas".
  87.  
  88. EVENT-ORIENTED PROGRAMMING
  89. --------------------------
  90.  
  91.   The interface is intended to be used in an event-oriented program. The
  92. basic ideas are:
  93.  
  94.   The program does not follow a predefined fluxogram, but is commanded by
  95. the user, that generates "events" by acting on the objects in the windows,
  96. what causes calls to the "callback" routines, where the program functional
  97. code is located.
  98.   Any "callback" subroutine can be called at any moment. In its initial
  99. code, it can be necessary for the routine to check the program status to
  100. determine what is to be done. The program status can be maintained in a set
  101. of global logical variables, and/or in the "textfield", "setting", and
  102. "menu" objects.
  103.   The "callback" routines have complete control of the machine while active.
  104. They can open or close windows using "open_window" and "close_window",
  105. draw in "canvas" objects using the normal graphical functions, print
  106. messages in "tty" (using "ttysw_output") or "message" objects (using
  107. "xv_set"), or anything else that does not corrupt the interface structures.
  108.   The user is never prompted for information in a way that blocks the
  109. program execution (it is possible, if necessary, through windows with
  110. exclusive access (see the file "exclusiv.inc"), but not recommended). The
  111. procedure for getting information from the user is to open a window with
  112. items to filled. "Callback" routines associated with the window objects
  113. update the program status and continue the execution, when and if the user
  114. commands.
  115.   The program never reads the keyboard or mouse directly (it is possible,
  116. using the normal functions and the "mickey" module functions, but also not
  117. recommended). All the inputs from the user are received as events and actions
  118. on the objects.
  119.  
  120.   The objects call "callback" routines by three mechanisms, associated with
  121. the object attributes:
  122.  
  123. "notify_handler": A "callback" routine, called when:
  124. - "frame": The window is closed.
  125. - "texfield": The return key is pressed, at the end of an edition.
  126. - "canvas": The window is redrawn, on the opening and resizing of the
  127.   window.
  128. - Other objects: The left mouse button is pressed over the object.
  129.  
  130. "event_handler": A "callback" routine, called when the state of the mouse
  131. changes over the object, or when a key is pressed, with the mouse pointer
  132. over the object.
  133.  
  134. "menu_name": Name of a "menu", opened with the right mouse button pressed
  135. over the object. The menus normally have an associated "notify handler",
  136. called when a selection is done. It is also possible to open a menu
  137. programatically, using the "menu_show" procedure. The items of a menu can
  138. have an associated "item_submenu" (name of another menu),also opened with
  139. the right mouse button. The same is valid for submenus of any order. The
  140. left mouse button always cause the selection of the present item, even if
  141. there are submenus. The central mouse button (or both right and left
  142. buttons simultaneously) cause the dismiss of menus without a call to the
  143. menu "notify_handler".
  144.  
  145.   The "callback" routines have always the same structure. They are far
  146. procedures receiving a single argument, that is the calling object pointer.
  147. Using this pointer, the parameters of the calling object can be accessed.
  148.  
  149. EVENTS
  150. ------
  151.  
  152.   The "event_handler" routines can read the event that caused the call in
  153. the global variable "ie_code". Its meanings are:
  154.  
  155. - Mouse events: "ie_code" contains:
  156.   LOC_MOVE: Movement.
  157.   LOC_DRAG: Movement with some button pressed.
  158.   MS_LEFT: Left button pressed.
  159.   MS_MIDDLE: Central button pressed.
  160.   MS_RIGHT: Right button pressed.
  161.   The state of the mouse buttons (as returned by the DOS interrupt 33) is in
  162. the global variable "ie_shiftcode".
  163.   The event names above are predefined constants. In the general case for
  164. button events, "ie_code"=1000+10*<buttons before>+<buttons after>.
  165.   The mouse position, relative to the object upper left corner, is in the
  166. global variables "ie_locx" and "ie_locy". The absolute mouse position is also
  167. available in the variables "mousex" and "mousey", defined in the "mickey"
  168. module.
  169.  
  170. - Keyboard events: "ie_code" contains the ASCII code of the pressed key. In
  171. the case of keys with extended codes, "ie_code" contains 2000+2nd code.
  172. With the mouse emulator in operation (see the MOUSE DRIVER section), events
  173. that are used by the emulator are not generated, unless the ScrollLock key is
  174. active, what returns the keyboard to normal operation.
  175.  
  176.   Some events interpreted by the interface are not passed to the
  177. "event_handlers". Only the "canvas" objects receive all the events. In any
  178. way, there is no much sense in detecting events over other objects.
  179.  
  180. WINDOWS
  181. -------
  182.  
  183.   There is always an active window, which "frame" pointer is equal to  the
  184. global variable "active_w". The active window is the last opened by the
  185. program, or where a button mouse was pressed most recently.
  186.   To press a mouse key over a window partially covered causes its movement
  187. to the foreground before the processing of the event. The procedures
  188. "open_window", "close_window", "xv_set", "ttysw_output", and "xv_main_loop"
  189. also move their parameter window to the foreground and turn them into the
  190. active window.
  191.   Windows are closed with the procedure "close_window", or by pressing the
  192. central mouse button in the header or an empty area of the window.
  193. The "frame" parameter "adjust_exit" controls if the window can be closed by
  194. the central mouse button. To press simultaneously the right and left mouse
  195. buttons has the same effect.
  196.   Windows are always movable and resizable. Their minimum sizes are
  197. controlled by the "frame" parameters "dxmin" and "dymin". If the window
  198. contains objects with bitmaps or "tty" and "canvas" objects, these values
  199. shall be set to a value high enough to impede the window to be reduced
  200. below the size needed for these objects. The default minimum sizes are
  201. dxmin=99 and dymin=99 (100x100 pixels).
  202.   Objects of type "canvas" and "tty" can change in size to accommodate
  203. changes in their window sizes. This behavior can be controlled by the
  204. parameters "canvas_xext", "canvas_yext", "tty_xext", and "tty_yext", that
  205. control if the objects extend to the window right and bottom edges. As
  206. default, they do it.
  207.  
  208. GRAPHICAL OUTPUT
  209. ----------------
  210.  
  211.   Usually, graphical output is created with the normal Pascal and C
  212. procedures and functions, called from the "callback" routines. When the
  213. "callbacks" are called, the "viewport" is set to the last "canvas" of the
  214. active window, or by the active area of the active window if there is no
  215. "canvas" on it. It is possible to change the "viewport" to draw in other
  216. areas, but usually it is not necessary. The present "viewport" is contained
  217. in the parameter "gr_out" of the active window. When it points to a "canvas"
  218. area, there is a 1 pixel margin for the "canvas" border, so the usable area
  219. is from (0,0) to (dx-2,dy-2), where "dx" and "dy" are the canvas width and
  220. height parameters.
  221.   The mouse support is totally transparent. It is not necessary to turn off
  222. the mouse cursor to draw, as the "callbacks" are always called with the
  223. cursor off.
  224.   The simplest way of generating drawings correctly is from the "canvas"
  225. notify and event handlers. The "notify_handler" is called when the window
  226. is opened or resized. The code in it shall be able to reproduce the entire
  227. drawing, usually scaled to the window dimensions. The "event_handler" can
  228. cause editing functions in a drawing, provide cursor functions, etc.
  229.   Frequently it is desirable to draw in a "canvas" from other "callbacks".
  230. It is possible if the window containing the "canvas" is first turned into
  231. the active window.
  232.   There is no problem when the owner of the "callback" belongs to the same
  233. window, or to a menu called from a window object. If it is not the case,
  234. the "canvas" window can be activated with a call to "open_window". The
  235. operation can be impossible due to memory limitations, and so after the
  236. call the global boolean variable "xv_ok" shall be tested before any drawing
  237. operation.
  238.   It is frequently useful also to call a "canvas" "notify_handler" from
  239. another "callback" to cause a complete redrawing. The "canvas" window must
  240. be the active window for correct results. Note that a call to "open_window"
  241. when the window is not in the screen causes a call to the "canvas"
  242. "notify_handler". So, if the "canvas" window is not in the screen, the call
  243. to the "notify_handler" after the call to "open_window" is not necessary
  244. (it would cause two redrawings).
  245.   If the canvas window is on the screen (the "frame" attribute "mapped"
  246. contains this information), a safe procedure is to close all the windows
  247. that are above it before drawing. In Pascal, the code for this is:
  248. WHILE not active_w = <desired window "frame"> DO close_window(active_w);
  249.   If a "callback" routine changes the graphical configuration (LineStyle,
  250. TextStyle, etc.) and calls a procedure that draws interface objects, as
  251. "open_window" or "ttysw_output" (not recommended), it must replace the
  252. configuration as it was before the call (the initial defaults).
  253.   Only one "canvas" shall be put in each window, or only the last defined
  254. one will be automatically accessible. See the "rotor.pas" example to see how
  255. multiple "canvas" objects can be used in the same window.
  256.  
  257. TEXT OUTPUT
  258. -----------
  259.  
  260.   The procedure "ttysw_output" draws text in "tty" objects. The "tty"
  261. window is opened automatically. The procedure can be called from anywhere
  262. in the program. All the written text is stored in a buffer, and can be
  263. reviewed using the "tty" scrollbar. To read the buffer: The text starts at
  264. "bstart" and ends at "tend"-1. The buffer is circular, with the position "0"
  265. coming after the position "bsize".
  266.  
  267. BITMAP IMAGES
  268. -------------
  269.  
  270.   Objects of types "button" and "message" can display a bitmap image
  271. instead of a text label. If the parameter "icon_label" or "icon_msg" is
  272. set, the parameter "xv_label" is interpreted as the name of a file
  273. containing the image, that is loaded and plotted when the object is drawn.
  274. The supported format is the Windows BMP format, in 16 colors. If the global
  275. variable "use_palette" is set (default), the palette in the VGA screen is
  276. set to the palette in the bitmap. Note that the default Windows palette is
  277. not the same used in Turbo Pascal and C. The gray shade is darker, for
  278. example, so it may be necessary to change some of the default colors of the
  279. interface objects if Windows bitmaps are used. Bitmaps cannot have more
  280. than 640 pixels horizontally, and a "frame" containing bitmap objects must
  281. be big enough to contain the complete images. The bitmap plotting routine
  282. used internally, "drawbitmap", is available for other uses.
  283.  
  284. INTERPOSITION
  285. -------------
  286.  
  287.   It is possible to install an "interposer" procedure, called after each
  288. event, before the determination of the mouse cursor location. It is a special
  289. "callback" routine without parameters, and that is called with the cursor on.
  290.   The interposer routine can modify the event and the mouse position, open
  291. and close windows, open a menu, etc. It is necessary to turn off the cursor
  292. before calls to "open_window" or "ttysw_output", calling "cursor_off"
  293. ("mickey" module). It is not necessary to turn on the cursor on exit.
  294.   The "interposer" can implement utilities as "accelerator keys" (see modules
  295. hotkeys.int and tabkeys.int), help, event filtering, etc.
  296.   To activate: insert "interposer:=<procedure>;" somewhere after "xv_init".
  297.   To inactivate: "interposer:=nointerpose;"
  298.   Events generated in internal operations, as while a "textfield" is in
  299. edition, are not passed to the "interposer".
  300.  
  301. MEMORY USAGE
  302. ------------
  303.  
  304.   In the normal usage, the objects are allocated at the beginning of the
  305. program execution, and are kept until the end. Dynamic allocation is also
  306. possible. All the memory used for the interface objects is allocated in the
  307. heap. In the protected mode versions, the heap can use all the available
  308. extended (XMS) memory, and with an appropriate driver (as in GNU C), all
  309. the disk as virtual memory.
  310.   Window movement and reordering use additional memory, freed at the end of
  311. the operation. Window operations that need more memory than the available
  312. are refused, and a "beep" sounds. The global variable "xv_ok" turns into
  313. false or 0 when this occur. Programs shall avoid to put big windows above
  314. other windows, to minimize memory use. Large windows shall be put directly
  315. over the background.
  316.  
  317.   The objects allocate the amounts of heap memory listed below (Pascal
  318. version):
  319. - "SizeOf(xv_widget)" bytes (262).
  320. - The size of the strings used in the "menu" and "setting" items (Pascal only).
  321. - The size of the buffer used in "tty" objects ("bsize"+1 bytes).
  322. - The bitmap area in a "button" or "message" with a bitmap.
  323. - For a window that is in the screen and covering others, an area storing
  324.   the image covered. Images of window backgrounds and bitmaps are saved in
  325.   "figstruct" records or structures.
  326.   Programs that use dynamic allocation of objects shall contain object
  327. "destructors". A "destructor" is a procedure that deallocates the four
  328. first items listed above when the corresponding objects are "destroyed".
  329. The most usual procedure is to use a "destructor" as the "notify_handler"
  330. of a window "frame". In this way, the "destructor" is automatically called
  331. when the window is closed, and deallocates all its objects. The window area
  332. is automatically freed when the window is closed. New windows are created
  333. normally with calls to "xv_create". Note that the procedures "xv_create"
  334. and "item_create" allocate memory, and so can fail if there is not enough
  335. heap memory. See the example program "xbitmap.pas" for an example of how to
  336. use dynamic allocation.
  337.   Heap memory for the program can be allocated or deallocated at any
  338. moment. The Pascal  "Mark" and "Release" functions cannot be used.
  339.  
  340. COLORS AND GRAPHICS MODES
  341. -------------------------
  342.  
  343.   All the graphics boards and modes supported by the BGI drivers are
  344. accepted. The default colors are used in the EGA and VGA boards. In modes
  345. with two colors, a pattern of black and white dots is used in place of the
  346. gray color in the objects. The colors can be changed changing some global
  347. constants, or changing the palette.
  348.  
  349. SOME RECOMMENDATIONS
  350. --------------------
  351.  
  352.   Use the "x_make" program to generate the initial version of an interface,
  353. editting it as needed after to fill the "callbacks" and other alterations.
  354. Keep the structure that "x_make" generates.
  355.   Note that some objects that are never referenced, as buttons, must not be
  356. declared separately. "x_make" declares all the objects for clarity.
  357.   Do not use dynamic object allocation, windows with exclusive access, or
  358. interposition unnecessarily.
  359.   Keep rigorously the philosophy that the commands in the windows can be
  360. acessed at any instant. The most that the program shall do to impede access
  361. to an object is to close the window that contains it.
  362.   Verify carefully the effects of commands given by the user out of the
  363. expected order. Make the program warn the user in these cases and recommend
  364. the correct action.
  365.   Warnings of possibly incorrect or dangerous operations, asking for immediate
  366. confirmation, are valid uses for windows with exclusive access.
  367.   Make a window as the main window, putting it over the background and
  368. impeding its closing with the mouse (<frame>^.adjust_exit:=FALSE).
  369.   Use smaller windows for dialog with the user. At least one window shall
  370. contain a "tty", used for messages to the user, listings, etc.
  371.   Create a menu, always accesible, that opens any of the program windows. It
  372. is the simplest mean to avoid possible "deadlocks" in a complex program.
  373.  
  374. FILES, COMPILATION, AND DIRECTORIES
  375. -----------------------------------
  376.  
  377.   For compilation with Turbo Pascal (Version 7.0), the files "xview.tpu"
  378. and "mickey.tpu" (or the equivalent .tpp files for protected mode programs)
  379. must be accessible.
  380.   For execution, the BGI driver and the font "litt.chr" must be in the local
  381. directory, or in a path pointed by the DOS environment variable "TPBGI".
  382. Bitmaps used in buttons or messages, or drawn by the "drawbitmap" routine,
  383. must be in the local directory, or in a path pointed by the DOS environment
  384. variable "BMP".
  385.   For compilation in C/C++, see instructions in the file "xview.h".
  386.  
  387. LICENSING AND USE OF THE XVIEW-PC INTERFACE
  388. -------------------------------------------
  389.  
  390.   The use of the interface is free for educational and academic purposes,
  391. not commercial. The compressed file XV_PC*.ZIP can be distributed freely,
  392. respected these restrictions, and that it cannot be changed in any way
  393. without the consent of the author.
  394.   The code is offered "as is". The author believes that everything is working
  395. correctly, but cannot be responsible for eventual losses caused by
  396. imperfections or bugs in the code.
  397.   For commercial use, the author is requiring a registration fee of US$ 50.
  398. Registered users have the right to receive the source code of the interface.
  399.   For the clarifying of doubts, information about detected problems, etc.,
  400. the interested shall contact the author:
  401.  
  402. Dr. Antonio Carlos Moreirao de Queiroz
  403. COPPE/UFRJ - Programa de Engenharia Eletrica
  404. CP 68504
  405. 21945-970 Rio de Janeiro, RJ, Brasil
  406. e-mail: acmq@coe.ufrj.br
  407.  
  408. CONSTANTS AND VARIABLES DEFINED IN THE XVIEW UNIT
  409. -------------------------------------------------
  410.  
  411.   This is a translation of the unit header "xview.int", that is commented
  412. in Portuguese.
  413.   The variables below marked with "#" are object parameters that usually
  414. are changed immediately after the object creation. All have safe default
  415. values.
  416.   The variables marked with "*" are reserved for internal use, and shall
  417. not be modified in the normal interface operation.
  418.   The others can be changed at any moment.
  419.   For more information about the C/C++ version, see the file "xview.h".
  420. The variables and functions of are mostly a direct translation of the Pascal
  421. versions.
  422.  
  423. CONST
  424. LOC_MOVE=256;    {event: mouse moved}
  425. LOC_DRAG=257;    {event: mouse moved with pressed button(s)}
  426. MS_LEFT=1001;    {event: left mouse button pressed}
  427. MS_MIDDLE=1004;  {event: middle mouse button pressed}
  428. MS_RIGHT=1002;   {event: right mouse button pressed}
  429. m_itens=20;      {maximum number of items in menus and setting (only 16 in
  430. these)}
  431. m_chars=60;      {characters in strings}
  432. mrgx=5;          {lateral and bottom window margins}
  433. mrgy=22;         {upper window margin}
  434.  
  435. CONST
  436. normal_bsize:WORD=1000;   {"bsize" (tty) attributed by "xv_create"}
  437. normal_length:INTEGER=16; {"value_length" (textfield) attributed by
  438. "xv_create"}
  439. wallpaper:BOOLEAN=FALSE;       {if the screen background is retained}
  440. c_normal:INTEGER=lightgray;    {color of object background}
  441. c_active:INTEGER=green;        {color of pressed buttons}
  442. c_light:INTEGER=white;         {color of lighted corners}
  443. c_shadow:INTEGER=black;        {color of shadowed corners}
  444. c_white:INTEGER=white;         {default "back_color"}
  445. c_black:INTEGER=black;         {default "fore_color"}
  446. c_overwrite:INTEGER=lightred;  {edition color for "textfields"}
  447. c_edit:INTEGER=blue;           {selection color for "textfields"}
  448. c_insert:INTEGER=yellow;       {insertion color for "textfields"}
  449. c_hatch:INTEGER=cyan;          {color of the background pattern}
  450. type_hatch:INTEGER=XHatchFill; {type of the background pattern}
  451. use_palette:BOOLEAN=TRUE;      {if the bitmap palettes are used}
  452. normal_client_data:POINTER=nil;{"client_data" attributed by "xv_create"}
  453. nlines:INTEGER=60;             {* number of lines in each image block}
  454.  
  455. TYPE
  456. figstruct=RECORD                     {structure for images}
  457.   blocks:INTEGER;                    {number of image blocks-1}
  458.   blocksize,lastblocksize:WORD;      {size of the allocated image blocks}
  459.   v:ARRAY[0..2000] of POINTER;       {only allocated until "blocks"}
  460. END;
  461. ptrfig=^figstruct;                   {image pointer}
  462. Xv_opaque=^xv_widget;                {generic object}
  463. xv_handler=PROCEDURE(pt:Xv_opaque);  {"callback" procedure}
  464. xv_label_type=STRING[m_chars];       {all strings}
  465. tty_buffer=ARRAY[0..65534] OF CHAR;  {"tty" buffer. Only "bsize"+1 bytes
  466. are allocated and used}
  467. xv_package=(frame,button,textfield,setting,message,canvas,tty,menu);
  468. xv_widget=RECORD
  469.   {Parameters used in all the objects}
  470.   xv_label:xv_label_type;         {# title}
  471.   x,y,dx,dy:INTEGER;              {# position and size}
  472.   fore_color,back_color:INTEGER;  {# colors}
  473.   owner:Xv_opaque;                {* owner "frame"}
  474.   next:Xv_opaque;                 {* next object}
  475.   menu_name:Xv_opaque;            {# associated menu}
  476.   notify_handler:xv_handler;      {# associated notify handler}
  477.   event_handler:xv_handler;       {# associated event handler}
  478.   client_data:POINTER;            {# pointer to other parameters}
  479.   {Specific parameters for each object}
  480.   CASE o_type:xv_package OF       {* object type}
  481.     frame:(over,under:Xv_opaque;  {* neighbor windows}
  482.       Pw:ptrfig;                  {* covered image}
  483.       areaw:LONGINT;              {* window area size}
  484.       dxmin,dymin:INTEGER;        {# minimum dimensions}
  485.       interfere:BOOLEAN;          {* internal use}
  486.       mapped:BOOLEAN;             {* if it is on the screen}
  487.       adjust_exit:BOOLEAN;        {# if central button can close}
  488.       mouse_obj:Xv_opaque;        {# object pointed by the mouse when the
  489. window is opened. nil if none (default)}
  490.       gr_out:ViewPortType);       {* associated "ViewPort"}
  491.     button:(icon_label:BOOLEAN;   {# if "xv_label" is a file name}
  492.       Pimageb:ptrfig);            {* button bitmap}
  493.     message:(icon_msg:BOOLEAN;    {# if "xv_label" is a file name}
  494.       Pimagem:ptrfig);            {* message bitmap}
  495.     textfield:(panel_value:xv_label_type;  {# text value}
  496.       panel_real:REAL;            {# real value}
  497.       panel_int:INTEGER;          {# integer value}
  498.       min_value,max_value:INTEGER;{# limits for integers}
  499.       value_length:INTEGER;       {# edition field length}
  500.       field_type:(text_field,real_field,int_field)); {# type}
  501.     setting:(itens_setting:INTEGER; {* number of itens}
  502.       sel_setting:INTEGER;          {# selection}
  503.       item_setting:array[1..m_itens] OF ^xv_label_type;{* item names}
  504.       exclusive:BOOLEAN);           {# if the selection is exclusive}
  505.     canvas:(can_xext,can_yext:BOOLEAN);  {# if the "canvas" extends to the
  506. window borders}
  507.     tty:(tty_xext,tty_yext:BOOLEAN; {# if the "tty" extends to the window
  508. borders}
  509.       xc,yc:INTEGER;    {* graphical cursors}
  510.       bsize:WORD;       {* buffer size}
  511.       bstart:WORD;      {* buffer start}
  512.       tstart:WORD;      {* visible text start}
  513.       bcsr:WORD;        {* visible text end}
  514.       tend:WORD;        {* text end+1}
  515.       dxtty:INTEGER;    {* panel width}
  516.       Pb:^tty_buffer);  {* buffer pointer}
  517.     menu:(itens_menu:INTEGER; {* number of items}
  518.       sel_menu:INTEGER;       {# selected item}
  519.       item_menu:ARRAY[1..m_itens] OF ^xv_label_type; {* item names}
  520.       item_submenu:ARRAY[1..m_itens] OF Xv_opaque);  {# submenus}
  521.   END;
  522.  
  523. VAR
  524.   insert:BOOLEAN;          {if text is inserted in "textfields"}
  525.   xv_end:BOOLEAN;          {ends "xv_main_loop"}
  526.   ulttxt:xv_label_type;    {last text entered in "textfields"}
  527.   xv_ok:BOOLEAN;           {* result of the last window operation}
  528.   ie_locx,ie_locy:INTEGER; {* mouse position relative to active object or
  529. window}
  530.   ie_code:INTEGER;         {* event code}
  531.   ie_shiftcode:INTEGER;    {* mouse buttons state}
  532.   active_w:Xv_opaque;      {* the active window "frame"}
  533.   active_o:Xv_opaque;      {* active object}
  534.   w_base:Xv_opaque;        {* base window for "xv_create"}
  535.   o_base:Xv_opaque;        {* base object for"item_create"}
  536.   redrawing_frame:BOOLEAN; {* if a window is being redrawn}
  537.   interposer:PROCEDURE;    {routine called after each event}
  538.  
  539. {Public subroutines. Only the first four are of essential use}
  540.  
  541. PROCEDURE xv_init(board,mode:INTEGER);
  542. {General initialization. Enters the specified graphics mode, initializes
  543. colors and mouse, and sets "active_w" to "nil"}
  544.  
  545. FUNCTION xv_create(obj_type:xv_package):Xv_opaque;
  546. {Allocates and initializes with default values an object. Returns its
  547. "handle" pointer.
  548. Allocates the buffer "tty_buffer" of "tty" objects, with
  549. "GetMem(Pb,bsize+1)".
  550. Must be called once for each object, beginning by the window "frame".
  551. Does not test possible "heap overflow"}
  552.  
  553. PROCEDURE item_create(txt:xv_label_type);
  554. {Creates "menu" or "setting" items.
  555. Call once for each item, immediately after "xv_create". The items are
  556. enumerated from 1. In the Pascal version, the texts are allocated with
  557. GetMem(<item>,Length(txt)+1). Does not test "heap overflow".}
  558.  
  559. PROCEDURE xv_main_loop(w:Xv_opaque);
  560. {Opens a window and starts the cycle wait for event - process event.
  561. Ends when all the windows are closed or when "xv_end" is true.
  562. Does not deallocates the objects at exit.
  563. Can be called more than once to create a special window. See the files
  564. "exclusiv.inc" and "notice.h" for examples.}
  565.  
  566. PROCEDURE open_window(w:Xv_opaque);
  567. {Opens a window, turning it the active one.
  568. The selected window is opened and/or put in the foreground.
  569. Causes calls to "canvas" "notify_handlers" if the window is not in the
  570. screen.
  571. Can be called at any time after "xv_init". Calls before "xv_main_loop" can
  572. be used to start a program with several open windows}
  573.  
  574. PROCEDURE close_window(w:Xv_opaque);
  575. {Closes a window. Causes a call to the "frame" "notify_handler", if
  576. installed. Can also be called at any moment after "xv_init". The window is
  577. moved to the foreground and erased. The window objects are kept allocated}
  578.  
  579. PROCEDURE ttysw_output(terminal:Xv_opaque; text:STRING);
  580. {Writes a text in a "tty" terminal. The "tty" window is opened and turned
  581. the active window}
  582.  
  583. PROCEDURE back;
  584. {Circulates back the windows, moving the present active window to the
  585. background. Useful in window menus}
  586.  
  587. PROCEDURE xv_set(obj:Xv_opaque; new_label:xv_label_type);
  588. {Changes the "xv_label" of an object. The window object is turned the
  589. active window. Mainly used to change "messages". Can be used to update also
  590. other parameters, as "textfield" values, directly set before the call}
  591.  
  592. PROCEDURE menu_show(obj:Xv_opaque);
  593. {Opens a menu at the mouse location (mousex, mousey). It is better to
  594. associate menus to the objects. This is the routine used internally to open
  595. menus. A typical use is to make a button open a menu, by calling
  596. "menu_show" from the button "notify_handler"}
  597.  
  598. PROCEDURE draw_object(obj:Xv_opaque; active:BOOLEAN);
  599. {Draws an object. Can be used causing the fast redraw of a window (use the
  600. "frame" as parameter), as a more powerful version of "xv_set". "active"
  601. affects only buttons. For objects that are not "frames", the background is
  602. not erased, and labels are only drawn if the global variable
  603. "redrawing_frame" is true. This routine is used internally. Its use is not
  604. recommended}
  605.  
  606. PROCEDURE Nothing(obj:Xv_opaque);
  607. {Default "notify_handler" and "event_handler". No action. Can be used to
  608. inactivate "callbacks"(unusual)}
  609.  
  610. PROCEDURE nointerpose;
  611. {Default "interposer". No action. Can be used to inactivate the "interposer"}
  612.  
  613. PROCEDURE wait_button;
  614. {Waits until the mouse buttons are released (unusual).}
  615.  
  616. FUNCTION Cpct(x:REAL):STRING;
  617. {Returns a more compact form of a real number (Pascal version only)}
  618.  
  619. PROCEDURE DrawBitmap(x,y:INTEGER; VAR dw,dh:INTEGER; VAR Pimg:POINTER;
  620. filename:xv_label_type);
  621. {Draws a Windows 16 colors bitmap at (x, y).
  622. If "Pmgi=nil", loads the bitmap from disk (BMP format) and, if possible,
  623. allocates memory and saves it in "Pimg^" as a "figstruct" structure.
  624. Posterior calls cause a faster drawing. The used memory is
  625. "FigureSize(0,0,dw,dh)" bytes.
  626. The dimensions "dw" and "dh" are returned (width-1 and height-1).
  627. It is used internally to draw "buttons" and "messages" with images.
  628. "Pimg" can be the address of another "figstruct" variable.
  629. Note that, as "PutImage" does not clips at the "viewport" limits, the
  630. window that contains bitmaps must be always of enough size to contain them}
  631.  
  632. {The routines below are used internally in operations involving images.
  633. They are also available for other uses}
  634.  
  635. FUNCTION FigureSize(x1,y1,x2,y2:INTEGER):LONGINT;
  636. {Memory needed for an image. Size of the "figstruct" structure}
  637.  
  638. PROCEDURE GetFigureMem(VAR p:ptrfig; dw,dh:INTEGER);
  639. {Allocates memory for an image. "dw" and "dh" are width-1 and height-1}
  640.  
  641. PROCEDURE FreeFigureMem(p:ptrfig);
  642. {Frees memory allocated previously with "GetFigureMem"}
  643.  
  644. PROCEDURE GetFigure(x1,y1,x2,y2:INTEGER; p:ptrfig);
  645. {Captures an image from the screen. "ptrfig" must be allocated with
  646. "GetFigureMem" before the call}
  647.  
  648. PROCEDURE PutFigure(x,y:INTEGER; p:ptrfig; bitblt:WORD);
  649. {Draws an image captured with "GetFigure" at (x, y) in the screen}
  650.  
  651. THE MOUSE DRIVER (MICKEY MODULE)
  652. --------------------------------
  653.  
  654.   The "mickey" unit or object file implements the mouse functions of the
  655. interface. Normally it is not necessary for a program to use the mouse
  656. functions directly, but they are available.
  657.   If the mouse is not installed, the keyboard emulates it. The cursor moves
  658. the arrow, and the buttons are substituted by:
  659.   left:    Return
  660.   central: Escape
  661.   right:   Space
  662.   The keys Home, PgDn, and PgUp change the cursor step.
  663.   With CapsLock or Shift (in the Pascal version) active, the buttons work
  664. in toggle mode.
  665.   ScrollLock suspends the emulation when active, allowing normal use of the
  666. keyboard.
  667.   The unit can be used alone. For the correct working of the emulator, the
  668. function "mouse_read" must be called regularly.
  669.  
  670. CONSTANTS AND VARIABLES DEFINED IN THE MICKEY UNIT
  671. --------------------------------------------------
  672.  
  673.   This is a translation of the file "mickey.int". See the file "mickey.h"
  674. for informations about the C/C++ version, that implements the same functions.
  675.  
  676. VAR
  677.   mousex,mousey,mouseb,x_factor:INTEGER; {mouse state}
  678.   cursor_active:BOOLEAN;
  679.  
  680. PROCEDURE mouse_init;              {Initialization}
  681. PROCEDURE cursor_on;               {Cursor on}
  682. PROCEDURE cursor_off;              {Cursor off}
  683. PROCEDURE mouse_read;              {Reads current state}
  684. PROCEDURE mouse_move(x,y:INTEGER); {Moves cursor}
  685. FUNCTION  mkbhit:BOOLEAN;          {Identical to KeyPressed (of kbhit), but
  686.                     do not report keys used by the mouse
  687.                     emulator, when active. Internal use}
  688.  
  689.  
  690. WHAT IS NEW
  691. -----------
  692.  
  693. Version 1.7: August 1994
  694.   - The GNU C version was added.
  695.   - Events used by the interface are not passed to the event handlers.
  696.   - Some changes were made in the examples and documentation.
  697.  
  698. Version 1.6b: May 1994 (updated in July 1994). Restricted distribution.
  699.   - The C version works with C or C++ with the same object files.
  700.   - Small bugs in the include files were corrected.
  701.   - The C example was modified.
  702.   - Added comments about the GNU C (djgpp) version.
  703.  
  704. Version 1.6a: April 1994.
  705.   - Keys with extended codes generate only one event (2000+2nd code).
  706.     This is the only change that may cause some changes in programs written
  707.     for the previous version.
  708.   - A version of the C object files compatible with C++ was added.
  709.   - The C versions were compiled with the "huge" model.
  710.   - The functions "kbhit()" (C), and "KeyPressed" (Pascal) now function
  711.     normally. The function "mkbhit" shall be used instead of them.
  712.   - When the mouse emulator is active, only the events used by it are not
  713.     generated (arrows, home, pgup, pgdn, cr, space, and esc).
  714.   - The documentation of the C version and all examples was translated to
  715.     English.
  716.   - Small bugs in the "textfield" editor (C version), in menu operations,
  717.     and in the "tty" were corrected.
  718.   - Word alignment is not necessary anymore.
  719.   - The "interposer" was included.
  720.   - The "textfield" editor and the Cpct function (Pascal) were modified.
  721.   - Source files with some utilities and examples were added (extkeys,
  722.     notice, exclusiv, hotkeys, tabkeys, rotor).
  723.  
  724. Version 1.6: First version distributed to the Internet, December 1993.
  725.  
  726. ACMQ - 03/08/94
  727.